package com.mm.mindmap.handler;


import com.mm.common.pipeline.PipelineHandler;
import com.mm.common.pipeline.Product;
import com.mm.common.utils.GZipUtil;
import com.mm.mindmap.chache.MindMapCache;
import com.mm.mindmap.domain.dto.MindMapDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
@Slf4j
public class LoadMindMap extends PipelineHandler {
    private final MindMapCache mindMapCache;

    @Override
    public Product process(Product product)  {
        Long mid = product.getData(Long.class);
        //读取mindMap的缓存
        MindMapDTO mindMap = mindMapCache.getMindMap(mid);

        //进行压缩Base64
        mindMap.setNodeList(GZipUtil.compressStrByBase64(mindMap.getNodeList()));

        if(mindMap == null){
            log.error("[getMindMapById] 获取导图失败");
            return Product.getAbnormal("[getMindMapById] 获取导图失败");
        }

        return Product.getNormal(mindMap);
    }
}
